#ifndef SIP_WTRESIPDLLITF_HPP__
#define SIP_WTRESIPDLLITF_HPP__

#include "WTResipDll/SipResipConfigure.hpp"
#include "WTResipDll/SipDialogKey.hpp"
#include "WTResipDll/SipWtTypes.hpp"
#include "resip/stack/SipMessage.hxx"

namespace wtsip{

class ISipDialogBase;
class ISipClnTransaction;
class ISipSrvTransaction;
class ISipClnTransactionCallback;
class ISipSrvTransactionListener;
class ISipDlgHandle;

class CSipDialogSet;
class CSipDialogBase;
class CSipUserAgent;


typedef std::auto_ptr<resip::SipMessage> CapSipMessage;
typedef resip::SipMessage CSipMessage;
typedef ISipClnTransaction* CpSipClnTransaction;
typedef ISipSrvTransaction* CpSipSrvTransaction;
typedef ISipClnTransactionCallback* CpSipClnTransactionCallback;
typedef ISipSrvTransactionListener* CpSipSrvTransactionListener;


//////////////////////////  class Transaction /////////////////////

class RESIP_PUBLIC ISipClnTransaction
{
public:
    typedef enum
    {
        ClnInitial,
        ClnProvisional,
        ClnCompleted,
        ClnFailed
    } EClnTranState;

public:
    virtual bool processIncoming(CapSipMessage msg) = 0;

    virtual bool cancel() = 0;

    virtual bool send(CapSipMessage msg) = 0;

    virtual bool registerCallback(CpSipClnTransactionCallback callback) = 0;

    virtual bool unregisterCallback(ISipClnTransactionCallback* callback) = 0;

    virtual bool bindDialog(CSipDialogBase* dialog) = 0;

    virtual const resip::Data& getTid() const = 0;

    virtual CSipDialogBase* getBindDlg() const = 0;

    virtual ISipClnTransaction::EClnTranState getState() const = 0;

    virtual bool hasCallback() const = 0;
};


class RESIP_PUBLIC ISipSrvTransaction
{
public:
    typedef enum
    {
        SrvInitial,
        SrvProvisional,
        SrvCompleted,
        SrvFailed
    } ESrvTranState;

public:
    virtual bool processIncoming(CapSipMessage msg) = 0;

    virtual bool send(CapSipMessage msg) = 0;

    virtual bool registerListener(CpSipSrvTransactionListener listener) = 0;

    virtual bool unregisterListener(CpSipSrvTransactionListener listener) = 0;

    virtual CapSipMessage createResponse(CSipMessage& msg, const ESipCodeType code, const std::string& reason) = 0;

    virtual bool bindDialog(CSipDialogBase* dialog) = 0;

    virtual CSipDialogBase* getBindDlg() const = 0;

    virtual ISipSrvTransaction::ESrvTranState getState() const = 0;

    virtual const resip::Data& getTid() const = 0;

    virtual bool hasListener() const = 0;
};

//////////////////////// UserAgent Listener ///////////////////////

class RESIP_PUBLIC ISipUserAgentListener
{
public:

    virtual bool onRequest(ISipDialogBase& dlg, ISipSrvTransaction& srv, CapSipMessage msg) = 0;

    virtual bool onRequest(ISipSrvTransaction& srv, CapSipMessage msg) = 0;

    //virtual bool onResponse(ISipDialogBase& dlg, ISipClnTransaction& cln, CapSipMessage msg) = 0;

    //virtual bool onResponse(ISipClnTransaction& cln, CapSipMessage msg) = 0;
};


///////////////////////  class Dialog ///////////////////////////

class RESIP_PUBLIC ISipDialogBase
{
public:

    typedef enum
    {
        Initial,
        Established,
        Terminating
    } EDialogState;

    typedef enum 
    {
        Client,
        Server
    } EDialogRole;

public:

    virtual CapSipMessage createRequest(const SUri& tar, EMethodTypes mth, int expires, 
        bool incrSeq, CpSipClnTransaction& pCln) = 0;

    virtual CapSipMessage createRequest(const SUri& tar, const SUri& from, const SUri& to, 
        EMethodTypes mth, int expires, bool incrSeq, CpSipClnTransaction& pCln) = 0;

    virtual bool send(CapSipMessage msg) = 0;

    virtual bool dispatch(CapSipMessage msg) = 0;

    virtual bool registerHandle(ISipDlgHandle* handle) = 0;

    virtual bool unregisterHandle(ISipDlgHandle* handle) = 0;

    virtual bool terminate() = 0;

    virtual bool isShuttingdown() = 0;

    virtual bool hasHandle() = 0;

    virtual EDialogState getState() const = 0;

    virtual EDialogRole getRole() const = 0;

    virtual CSipDialogSet& getDialogSet() const = 0;

    virtual const CSipDialogKey& getDialogKey() const = 0;

    virtual const SUri& getRemoteUri() const = 0;

    virtual const SUri& getLocalUri() const = 0;

    virtual const SUri& getRemoteContact() const = 0;

};


//////////////////////////// Transaction Handle ////////////////////////
class RESIP_PUBLIC IDialogSetHandle
{
public:
    virtual bool isDialogRequest(CSipMessage& msg) = 0;
};

class RESIP_PUBLIC ISipClnTransactionCallback
{
public:

    virtual bool onDestroy(ISipClnTransaction& clntran) = 0;

    virtual bool onResponse(ISipClnTransaction& clntran, CapSipMessage msg) = 0;

    virtual bool onState(ISipClnTransaction& clntran, ISipClnTransaction::EClnTranState newState) = 0;
};

class RESIP_PUBLIC ISipSrvTransactionListener
{
public:
    virtual bool onRequest(ISipSrvTransaction& srvtran, CapSipMessage msg) = 0;

    virtual bool onDestroy(ISipSrvTransaction& srvtran) = 0;

    virtual bool onState(ISipSrvTransaction& srvtran, ISipSrvTransaction::ESrvTranState newState) = 0;

};


//////////////////////////// Dialog Handle ////////////////////////


class RESIP_PUBLIC ISipDlgHandle
{
public:

    //virtual bool onResponse(ISipDialogBase& dlg, ISipClnTransaction cln, CapSipMessage msg) = 0;

    virtual bool onRequest(ISipDialogBase& dlg, ISipSrvTransaction& srv, CapSipMessage msg) = 0;

    virtual bool onDestroy(ISipDialogBase& dlg) = 0;
};



}//namespace


#endif

